﻿namespace CodeSHARPer
{
    using System.Windows.Input;

    public class AppCommand
    {
        #region Static Constructor (Constructs static application commands)
        /// <summary>
        /// Define custom commands and their key gestures
        /// </summary>
        static AppCommand()
        {
            InputGestureCollection inputs = null;

            inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.F4, ModifierKeys.Alt, "Alt+F4"));
            AppCommand.Exit = new RoutedUICommand("Exit", "Exit", typeof(AppCommand), inputs);

            inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.F1, ModifierKeys.Control, "Ctrl+F1"));
            AppCommand.About = new RoutedUICommand("About", "About", typeof(AppCommand), inputs);

            AppCommand.LoadFile = new RoutedUICommand("Open ...", "LoadFile", typeof(AppCommand));
            AppCommand.SaveAll = new RoutedUICommand("Save All ...", "SaveAll", typeof(AppCommand));

            inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.W, ModifierKeys.Control, "Ctrl+W"));
            AppCommand.CloseFile = new RoutedUICommand("Close", "Close", typeof(AppCommand), inputs);

            AppCommand.ToogleToolbar = new RoutedUICommand("Show/Hide Tollbar", "ToogleToolbar", typeof(AppCommand));

            inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.R, ModifierKeys.Control, "Ctrl+R"));
            AppCommand.ToogleOutput = new RoutedUICommand("Show/Hide Output", "ToogleOutput", typeof(AppCommand), inputs);

            AppCommand.Preferences = new RoutedUICommand("Preferences", "Preferences", typeof(AppCommand));

            inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.F4, ModifierKeys.None, "F4"));
            AppCommand.References = new RoutedUICommand("References", "References", typeof(AppCommand), inputs);

            #region Text Edit Commands
            inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.A, ModifierKeys.Control, "Ctrl+A"));
            AppCommand.SelectAll = new RoutedUICommand("Select all items in a document", "SelectAll", typeof(AppCommand), inputs);

            inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.G, ModifierKeys.Control, "Ctrl+G"));
            AppCommand.GotoLine = new RoutedUICommand("Go to a specific line in a document", "GotoLine", typeof(AppCommand), inputs);

            inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.F, ModifierKeys.Control, "Ctrl+F"));
            AppCommand.FindText = new RoutedUICommand("Find specific text in a document", "FindText", typeof(AppCommand), inputs);

            inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.F3, ModifierKeys.None, "F3"));
            AppCommand.FindNextText = new RoutedUICommand("Find next occurrance of specific text in a document", "FindNextText", typeof(AppCommand), inputs);

            inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.F3, ModifierKeys.Shift, "Shift+F3"));
            AppCommand.FindPreviousText = new RoutedUICommand("Find previous occurrance of specific text in a document", "FindNextText", typeof(AppCommand), inputs);

            inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.H, ModifierKeys.Control, "Ctrl+H"));
            AppCommand.ReplaceText = new RoutedUICommand("Find and replace a specific text in a document", "FindReplaceText", typeof(AppCommand), inputs);
            #endregion Text Edit Commands

            inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.F5, ModifierKeys.None, "F5"));
            AppCommand.RunCode = new RoutedUICommand("Run", "RunCode", typeof(AppCommand), inputs);

            inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.K, ModifierKeys.Control, "Ctrl+K"));
            AppCommand.FormatDocumentCode = new RoutedUICommand("Format document", "FormatDocument", typeof(AppCommand), inputs);

            inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.K, ModifierKeys.Alt, "Alt+K"));
            AppCommand.FormatSelectionCode = new RoutedUICommand("Format selection", "FormatSelection", typeof(AppCommand), inputs);

            inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.OemPlus, ModifierKeys.Control, "Ctrl++"));
            AppCommand.IncreaseFontSize = new RoutedUICommand("Increase font size", "IncreaseFontSize", typeof(AppCommand), inputs);

            inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.OemMinus, ModifierKeys.Control, "Ctrl+-"));
            AppCommand.DecreaseFontSize = new RoutedUICommand("Decrease font size", "DecreaseFontSize", typeof(AppCommand), inputs);

            inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.D0, ModifierKeys.Control, "Ctrl+0"));
            AppCommand.NormalFontSize = new RoutedUICommand("Normal font size", "NormalFontSize", typeof(AppCommand), inputs);
        }
        #endregion Static Constructor

        #region CommandFramwork Properties (Exposes Commands to which the UI can bind to)
        /// <summary>Execute exit command.</summary>
        public static RoutedUICommand Exit { get; private set; }

        /// <summary>Execute about command.</summary>
        public static RoutedUICommand About { get; private set; }

        /// <summary>Execute file open command (without user interaction)</summary>
        public static RoutedUICommand LoadFile { get; private set; }

        /// <summary>Execute save all edited files command and current program settings</summary>
        public static RoutedUICommand SaveAll { get; private set; }

        /// <summary>Execute close active document command.</summary>
        public static RoutedUICommand CloseFile { get; private set; }

        /// <summary>Execute toogle toolbar command.</summary>
        public static RoutedUICommand ToogleToolbar { get; private set; }

        /// <summary>Execute toogle output command.</summary>
        public static RoutedUICommand ToogleOutput { get; private set; }

        /// <summary>Execute preferences command.</summary>
        public static RoutedUICommand Preferences { get; private set; }

        /// <summary>Execute references command.</summary>
        public static RoutedUICommand References { get; private set; }

        #region Text Edit Commands

        /// <summary>Execute go to line command.</summary>
        public static RoutedUICommand GotoLine { get; private set; }

        /// <summary>Execute find text command.</summary>
        public static RoutedUICommand FindText { get; private set; }

        /// <summary>Execute find next text command.</summary>
        public static RoutedUICommand FindNextText { get; private set; }

        /// <summary>Execute find previous text command.</summary>
        public static RoutedUICommand FindPreviousText { get; private set; }

        /// <summary>Execute replace text command on active document.</summary>
        public static RoutedUICommand ReplaceText { get; private set; }

        /// <summary>Execute select all text command on active document.</summary>
        public static RoutedUICommand SelectAll { get; private set; }
        #endregion Text Edit Commands

        /// <summary>Execute execute code command.</summary>
        public static RoutedUICommand RunCode { get; private set; }

        /// <summary>Execute format document code command.</summary>
        public static RoutedUICommand FormatDocumentCode { get; private set; }

        /// <summary>Execute execute format selection code command.</summary>
        public static RoutedUICommand FormatSelectionCode { get; private set; }

        /// <summary>Execute the increase font size command on current editor</summary>
        public static RoutedUICommand IncreaseFontSize { get; private set; }

        /// <summary>Execute the decrease font size command on current editor</summary>
        public static RoutedUICommand DecreaseFontSize { get; private set; }

        /// <summary>Sets the font size to the config size</summary>
        public static RoutedUICommand NormalFontSize { get; private set; }

        #endregion CommandFramwork_Properties
    }
}
